<admintpl file="header" />

<link href="__TMPL__Public/assets/css/infomation.css" rel="stylesheet" />
<link type="text/css" href="__PUBLIC__/js/select2/select2.min.css" rel="stylesheet" />
</head>
<body>
    <div class="wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('ConstructionLaisonNote/index')}">工程联系单管理</a></li>
            <li><a href="{:U('ConstructionLaisonNote/add')}">新增工程联系单</a></li>
            <li class="active"><a href="{:U('ConstructionLaisonNote/edit', array('id'=>I('request.id/s','')))}">编辑工程联系单</a></li>
        </ul>
        <section class="tab-pane active fade in" id="access">
            <div class="row">
                <div class="col-xs-12 col-md-12 col-lg-12">
                    <div class="panel panel-info">
                        <div class="panel-body">
                            <form method="post" class="form-horizontal form-inline tg js-ajax-form" action="{:U('ConstructionLaisonNote/edit_post')}" method="post">
                                <div class="row tg-header">
                                    <div class="col-md-12 text-center">
                                        <h3>工程联系单</h3>
                                        <hr />
                                    </div>
                                    <input type="hidden" name="id" value="{$result.id}" />
                                    <div class="col-md-12">
                                        <p class="pull-right tg-serialnum"><b>编号:</b><input class="input-xt" name="code" value="{$result.code}"/></p>
                                    </div>
                                    <div class="col-md-12">
                                        <p class="tg-to">
                                            <label>工程名称:</label>
                                            <input type="text" class="input-xt input-deptname"  value="{$job_name}"   />
                                        </p>
                                        <p class="pull-right">
                                            <label>建设单位:</label>
                                            <input class="input-xt input-deptname" type="text" value="杭州市中医院" readonly  />
                                        </p>
                                    </div>
                                </div>
                                <table class="table table-bordered">
                                    <tr>
                                        <td>
                                            <label>提交设计单位内容:</label>
                                            <textarea style="height:200px; width:100%" name="submit_content">{$result.submit_content}</textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label>设计回复及修改内容:</label>
                                            <textarea style="height:200px; width:100%" name="reply_and_modify">{$result.reply_and_modify}</textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label>变更后图纸的编号（设计院提交的电子版图纸文档）:</label>
                                            <div class="controls">
                                                <a class="btn upBtn btn-primary" href="javascript:void(0);">上传</a>
                                                <input type="file" id="upFile" name="upFile" style="display:none" />
                                            </div>
                                            <foreach name="results" item="vo">
                                                <div class='controls' style='margin-top:10px;margin-left:10px'>
                                                    <a class="fileDownload" path="{$vo.file_path}" name="{$vo.file_name}" data-type="{$vo.file_type}">{$vo.file_name}</a>

                                                    <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile' value="{$vo.id}">删除</a>
                                                </div>
                                            </foreach>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label>发送:</label>
                                            <select name="carbon_copy_department[]" id="carbon_copy_department" style="width:60%;" read class="select2" multiple="multiple" data-placeholder="选择抄送单位">
                                                <foreach name="data" item="vo">
                                                    <option value="{$vo.id}">{$vo.department_name}</option>
                                                </foreach>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                                <div class="form-actions">
                                    <button type="submit" class="btn btn-primary js-ajax-submit">{:L('SAVE')}</button>
                                    <if condition="$Role == 3 || $Role == 0">
                                        <input type="hidden" name="is_publish" id="is_publish" value="{$result.is_publish}">
                                        <input type="submit" class="btn btn-warning" id="btnPublish" value="发布">
                                    </if>
                                    <a class="btn btn-default" href="javascript:history.back(-1);">{:L('BACK')}</a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script src="__PUBLIC__/js/select2/i18n/zh-cn.js"></script>
    <script src="__PUBLIC__/js/select2/select2.min.js"></script>
    <script src="__PUBLIC__/js/select2/select2.default.js"></script>
    <script type="text/javascript">
        $("#carbon_copy_department").select2().val({$dept2}).trigger('change');
        /*
         * 多文件上传
         * @param reqUrl 请求地址
         * @param folder 上传后存储文件夹
         **/
   
        function UploadFile(reqUrl, folder){
            if($("#upFile").val() == ""){
                alert("请选择待上传文件！");
                return false;
            }
            $.ajaxFileUpload({
                url : reqUrl,
                secureuri : false, //安全协议
                fileElementId:'upFile', //id
                type : 'post',
                dataType : 'json',
                data:{
                    'folder'   : folder,
                    'ajax': 1
                },
                async : false,
                error : function(data,status,e) {
                    alert("服务器内部错误！");
                },
                success : function(json){
                    if (json.rtnType == 'T'){
                    	var Cts = "HAIHUI" + json.file_type;
						if(Cts.indexOf("image") > 0 ||  Cts.indexOf("pdf") > 0){
	                        html = "<div class='controls' style='margin-top:10px;margin-left:10px'>   \n"
	                            + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
	                            + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
	                            + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
	                            + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
	                            + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
	                            + " <a href="+json.rtnResult+" target='_blank' class='btn btn-warning btn-xs'>查看</a>\n"
	                            + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
	                            + "</div>";
	                        $(".controls:last").after(html);
	                    }else{
	                    	html = "<div class='controls' style='margin-top:10px;margin-left:10px'>   \n"
	                            + " <input type='hidden' name='filePath[]' value='"+json.rtnResult+"' />    \n"
	                            + " <input type='hidden' name='fileName[]' value='"+json.file_name+"' />    \n"
	                            + " <input type='hidden' name='file_size[]' value='"+json.file_size+"' />   \n"
	                            + " <input type='hidden' name='postfix[]' value='"+json.postfix+"' />     \n"
	                            + " <a href='#' target='_blank'><label class=\"fileDownload\" path=\""+json.rtnResult+"\" name=\""+json.file_name+"\">"+json.file_name+"</label></a>\n"
	                            + " <a href='javascript:void(0)' class='btn btn-danger btn-xs delFile'>删除</a> \n"
	                            + "</div>";
	                        $(".controls:last").after(html);
	                    }
                    } else {
                        alert(json.rtnMsg);
                    }
                },
                complete: function(xmlHttpRequest) {
                
                    $("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" style="display:none" />');
                    $("#upFile").on("change", function(){
                        UploadFile(reqUrl, folder);
                    });
                }
            });
        }

        
        $(document).ready(function(e) {


            // 选择图片
            $(document).on("click", ".upBtn", function(e) {
                $("#upFile").click();
            });
            // 文件选择器change事件
            $("#upFile").on("change", function(){
                UploadFile("{:U('ConstructionLaisonNote/upload')}", "construction_laison_note");
            });
            $(document).on("click", ".delFile", function(){
                if($(this).attr("value") != undefined){
                    delFile("{:U('ConstructionLaisonNote/delFile')}", $(this).attr("value"), $(this))
                } else {
                    $(this).closest("div").remove();
                }
            });
            // 拼接一行
            $(".addLine").click(function(){
                var html =  "<tr>" +
                            "   <td><input type=\"text\" name=\"job_name[]\" /></td>" +
                            "   <td><input type=\"text\" name=\"this_week_count[]\" /></td>" +
                            "   <td><input type=\"text\" name=\"next_week_count[]\" /></td>" +
                            "   <td>" +
                            "       <input type=\"hidden\" name=\"plan_type[]\" value=\""+$(this).attr("type")+"\" >" +
                            "       <a class=\"btn delLine\" href=\"javascript:void(0);\">删除</a>" +
                            "   </td>" +
                            "</tr>";
                $(this).closest("thead").next().append(html);
            });
            // 删除一行
            $(document).on("click", ".delLine", function(){
                $(this).closest("tr").remove();
            });
        });
    </script>
</body>
</html>